import { getTasks } from "@/api/task"

const gameTaskStore = {
  state: {
    isCollapse: false,
    taskList: [],
    detail: {},
  },
  actions: {
    getTaskList({ commit }, pagedata) {
      commit("GETTASKLIST", pagedata)
    },
    updateDetail({ commit }, data) {
      commit("UPDATEDETAIL", data)
    },
    unfoldChange({ commit }, val) {
      commit("GAMETASKUNFOLDCHANGE", val)
    }
  },
  mutations: {
    GETTASKLIST: async (state, pagedata) => {
      let res = await getTasks({ ...pagedata })
      state.taskList = res.data.list
      state.taskList.forEach(function (e) { e.showChild = false })
      if (!state.detail.id) {
        state.detail = res.data.list[0]
      }
    },
    UPDATEDETAIL: (state, data) => {
      state.detail = data
    },
    GAMETASKUNFOLDCHANGE: (state, val) => {
      state.isCollapse = val
    }
  }
}
export default gameTaskStore
